﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DinhMuc.Public;

namespace DinhMuc.DAL
{
   public class tblDinhMucDAL
    {
        clsConnect cn = new clsConnect();
      public DataTable bangDinhMuc()
      {
          return cn.LoadTableStore("sp_dinhmuc_select");
      }
      public DataTable bangDinhMuc(int soDH)
      {
          int para=1;
          string[] name =new string[para];
          object[] value =new object[para];
          name[0]="@soDH";
          value[0]=soDH;
          return cn.LoadTable_loc("sp_DSDinhMucTPBysoDH_select", name, value, para);
      }
      public DataTable dsNVL_bysoDH(int soDH)
      {
          int para = 1;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@soDH";
          value[0] = soDH;
          return cn.LoadTable_loc("sp_dsNVL_bysoDH", name, value, para);
      }
      public DataTable dsPL_bysoDH(int soDH)
      {
          int para = 1;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@soDH";
          value[0] = soDH;
          return cn.LoadTable_loc("sp_dsPL_bysoDH", name, value, para);
      }
      public DataTable dmNVL_bysoDH_NVL(int soDH,string maNVL)
      {
          int para = 2;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@soDH";
          name[1] = "@maNVL";
          value[0] = soDH;
          value[1] = maNVL;
          return cn.LoadTable_loc("sp_dmNVL_bysoDH_maNVL", name, value, para);
      }
      public DataTable dsDinhMucTP()
      {
          return cn.LoadTableStore("sp_DSDinhMucTP_select");
      }
      public void import(string sql, tblDinhMucPublic p)
      {
          int para = 10;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@A";
          name[1] = "@B";
          name[2] = "@C";
          name[3] = "@D";
          name[4] = "@E";
          name[5] = "@F";
          name[6] = "@G";
          name[7] = "@H";
          name[8] = "@I";
          name[9] = "@J";
          value[0] = p.SoDH;
          value[1] = p.MaNVL;
          value[2] = p.Dvt;
          value[3] = p.DmThoi;
          value[4] = p.DmTrangL1;
          value[5] = p.DmTrangL2;
          value[6] = p.DmIn;
          value[7] = p.DmChiaCuon;
          value[8] = p.DmCatDan;
          value[9] = p.Loai;
          cn.UpdateTable(sql, name, value, para);
      }
      public int ThemDinhMuc(tblDinhMucPublic p)
      {
          int para = 10;
          string[] name = new string[para];
          object[] value = new object[para];        
          name[0]="@soDH";
          name[1]="@maNVL";
          name[2]="@DVT";
          name[3]="@dmThoi";
          name[4]="@dmTrangL1";
          name[5]="@dmTrangL2";
          name[6]="@dmIn";
          name[7]="@dmChiaCuon";
          name[8]="@dmCatDan";
          name[9] ="@loai";
          value[0]=p.SoDH;
          value[1]=p.MaNVL;
          value[2]=p.Dvt;
          value[3]=p.DmThoi;
          value[4]=p.DmTrangL1;
          value[5]=p.DmTrangL2;
          value[6]=p.DmIn;
          value[7]=p.DmChiaCuon;
          value[8]=p.DmCatDan;
          value[9] =p.Loai;
          return cn.UpdateTableStore("sp_dinhMuc_insert", name, value, para);
      }
      public int suaDinhMuc(tblDinhMucPublic p)
      {
          int para = 10;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@ID";          
          name[1] = "@maNVL";
          name[2] = "@DVT";
          name[3] = "@dmThoi";
          name[4] = "@dmTrangL1";
          name[5] = "@dmTrangL2";
          name[6] = "@dmIn";
          name[7] = "@dmChiaCuon";
          name[8] = "@dmCatDan";
          name[9] = "@loai";
          value[0] = p.Id;          
          value[1] = p.MaNVL;
          value[2] = p.Dvt;
          value[3] = p.DmThoi;
          value[4] = p.DmTrangL1;
          value[5] = p.DmTrangL2;
          value[6] = p.DmIn;
          value[7] = p.DmChiaCuon;
          value[8] = p.DmCatDan;
          value[9] = p.Loai;
          return cn.UpdateTableStore("sp_dinhMuc_update", name, value, para);
      }
      public int xoaDinhMuc(int ID)
      {
          int para = 1;
          string[] name = new string[para];
          object[] value = new object[para];
          name[0] = "@ID";
          value[0] = ID;
          return cn.UpdateTableStore("sp_dinhMuc_delete_row", name, value, para);
      }
      public DataTable LoadToComBoBox_soDH()
      {
          DataTable dt = cn.LoadTableStore("sp_donhang_select");
          return dt;
      }
      public DataTable LoadToComBoBox_maNVL()
      {
          DataTable dt = cn.LoadTableStore("sp_nguyenVatLieu_select");
          return dt;
      }
    }
}
